package com.jsbs.iam.common.core.dto;

import com.jsbs.iam.common.core.utils.Json;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 分页查询父类，分页基本信息
 * <p> 继承之后就会自动分页
 * @author gu
 * @date 2020/6/29 19:00
 */
public class PageRequest implements Serializable {

    private static final long serialVersionUID = -4659610479395081875L;

    /**
     * 默认页长
     */
    public static final int DF_PAGE_SIZE = 10;

    @NotNull(message = "分页大小不能为空")
    @Range(min = 0, max = 1000, message = "每页大小为0-1000")
    private Integer pageSize;

    @NotNull(message = "页数不能为空")
    private Integer pageNum;

    private Integer total;

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }
    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void initPage() {
        if (pageNum == null || pageNum < 1) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = DF_PAGE_SIZE;
        }
    }

    @Override
    public String toString() {
        return Json.toJsonString(this);
    }
}
